import { Router, ActivatedRoute, ParamMap, NavigationEnd } from '@angular/router';
import { EquipmentService } from './../services/equipment';
import { Component, OnInit } from '@angular/core';
import { NzMessageService } from 'ng-zorro-antd';
import { Globals } from './../../../shared/global';

@Component({
  selector: 'ree-list',
  templateUrl: './list.component.html',
  styleUrls: ['./list.component.scss']
})
export class ListComponent implements OnInit {

  devicesList = [];
  isVisible = false;
  activeTabIndex = 0;
  selectedOption;
  searchOptions = [
    { value: 'jack', label: 'Jack' },
    { value: 'lucy', label: 'Lucy' },
    { value: 'tom', label: 'Tom' }
  ];

  filter = {
    deviceModel: '',
    deviceSidOrModel: '',
    dealerAccounts:'',
    customerAccounts: ''
  }

  constructor(
    private global: Globals,
    private equipmentService: EquipmentService,
    private router: Router,
    private message: NzMessageService,
    private route: ActivatedRoute,
  ) { }

  ngOnInit() {
    this.route.paramMap.subscribe(
      paramMap => console.log(paramMap)
    );
    this.getdevicesList(this.activeTabIndex)
  }

  getOdd(e) {
    this.getdevicesList(e)
  }

  getdevicesList(activeTabIndex) {
    this.equipmentService.getdevicesList(activeTabIndex).then(data => {
      this.devicesList = data;
    })
  }

  showModal = () => {
    this.isVisible = true;
  }

  confirmBind = (e) => {
    console.log('点击了确定');
    this.isVisible = false;
    this.router.navigateByUrl("work/equipment/bind")
  }

  cancelBind = (e) => {
    console.log(e);
    this.isVisible = false;
  }

  confirmDelete() {
    this.message.info('click cancel')
  }

  cancelDelete() {
    this.message.info('click cancel')
  }

  skipToCreate() {
    this.router.navigateByUrl("work/equipment/createDevice");
    this.global.paths.path.push({ name: "新建设备", route: null })
  }

  ngOnDestroy() {
    //this.global.paths.path.pop()
  }
}
